<template>
  <div>
    <div class="header">
      <van-nav-bar @click-left="$router.back()">
        <template #left>
          <van-icon name="arrow-left" size="20" color="black" />
          返回
        </template>
        <template #title> 添加联系人 </template>
      </van-nav-bar>
    </div>
    <div class="main">
      <van-address-edit
        :area-list="areaList"
        show-postal
        show-delete
        show-set-default
        show-search-result
        :search-result="searchResult"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
        @change-detail="onChangeDetail"
      />
    </div>
  </div>
</template>

<script>
import {AddressAdd} from "../../api/massage";
import Vue from "vue";
import { AddressEdit } from "vant";
import { areaList } from "@vant/area-data";
Vue.use(AddressEdit);
export default {
  data() {
    return {
      areaList, //地区列表
      searchResult: [],
      addressID: null,
    };
  },
  created() {},
  methods: {
    onSave(AddressInfo) {
      console.log(AddressInfo);
      // this.addressID = AddressInfo.id;
      // console.log(this.addressID);
      AddressAdd({
        userid: localStorage.getItem("userid"),
        name: AddressInfo.name,
        tel: AddressInfo.tel,
        province: AddressInfo.province,
        city: AddressInfo.city,
        county: AddressInfo.county,
        addressDetaill: AddressInfo.addressDetaill,
        isDefault: AddressInfo.isDefault,
      }).then((data) => {
        console.log(data);
      });
      this.$router.back()
    },
    onDelete() {
      //   Toast("delete");
      console.log(1);
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style>
</style>